var __extends =
    (this && this.__extends) ||
    (function () {
      var t = function (e, o) {
        return (t =
          Object.setPrototypeOf ||
          ({ __proto__: [] } instanceof Array &&
            function (t, e) {
              t.__proto__ = e;
            }) ||
          function (t, e) {
            for (var o in e)
              Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
          })(e, o);
      };
      return function (e, o) {
        function n() {
          this.constructor = e;
        }
        if ("function" != typeof o && null !== o)
          throw new TypeError(
            "Class extends value " + String(o) + " is not a constructor or null"
          );
        t(e, o),
          (e.prototype =
            null === o
              ? Object.create(o)
              : ((n.prototype = o.prototype), new n()));
      };
    })(),
  MountsMainController = (function (t) {
    function e() {
      var e = t.call(this) || this;
      return (
        e.btn_mounts_fanhui.on(Laya.Event.CLICK, e, e.backMethod),
        e.btn_mounts_xysm.on(Laya.Event.CLICK, e, e.lookXYSM),
        e.btn_mounts_xunyang.on(Laya.Event.CLICK, e, e.onDidClickXunYangAction),
        (e.list_mounts.vScrollBarSkin = ""),
        (e.list_mounts.selectEnable = !0),
        e.list_mounts.on(Laya.Event.CLICK, e, e.onClickListMounts),
        (e.list_mounts.renderHandler = new Laya.Handler(
          e,
          e.onHandlerUpdateItem
        )),
        WebSocketService.addListener({
          caller: e,
          code: 4423,
          method: e.onLoadMountsListData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 4424,
          method: e.onLoadBuyMountsData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 4425,
          method: e.onLoadOperateMountsData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 4419,
          method: e.onLoadMySelfMountsData,
        }),
        WebSocketService.addListener({
          caller: e,
          code: 4420,
          method: e.onLoadXuYangMountsData,
        }),
        e
      );
    }
    return (
      __extends(e, t),
      (e.showMountsMainView = function () {
        return (
          null == this.mountsV && (this.mountsV = new e()),
          WebSocketService.send({ c: 4423 }),
          WebSocketService.send({ c: 4419 }),
          this.mountsV
        );
      }),
      (e.prototype.onLoadMountsListData = function (t) {
        if (0 == t.code) {
          for (var e = void 0, o = [], n = 0; n < t.data.length; n++) {
            var i = t.data[n];
            (e = {
              label_mounts_name: { text: i.n },
              g: i.g,
              hid: i.hid,
              id: i.id,
              n: i.n,
              t: i.t,
              s: i.s,
            }),
              o.push(e);
          }
          this.list_mounts.dataSource = o;
        } else ToastView.toastView(t.msg);
      }),
      (e.prototype.onClickListMounts = function (t) {
        var e = this.list_mounts.selectedItem;
        "" != t.target.name &&
          ("btn_mounts_lingqu" == t.target.name
            ? "领养" == t.target.label
              ? 1 == e.t
                ? WebSocketService.send({ c: 4424, d: { id: e.hid } })
                : NormalDialog.showNormalDialog(
                    "确定消耗" + e.g + "金币领养\n" + e.n + "？",
                    this,
                    this.onNormalSureLingYangClick
                  )
              : "出战" == t.target.label
              ? WebSocketService.send({ c: 4425, d: { id: e.id, t: 2 } })
              : "休息" == t.target.label &&
                WebSocketService.send({ c: 4425, d: { id: e.id, t: 1 } })
            : MountsDetailsDialog.showMountsDetailDialog(e.hid));
      }),
      (e.prototype.onHandlerUpdateItem = function (t, e) {
        var o = t.dataSource,
          n = t.getChildByName("label_mounts_name"),
          i = t.getChildByName("label_mounts_lvl"),
          a = t.getChildByName("btn_mounts_lingqu");
        1 == o.t
          ? (n.color = "#228B22")
          : 2 == o.t
          ? (n.color = "#FF00FF")
          : 3 == o.t && (n.color = "#DAA520"),
          Global.roleLvl < 20
            ? ((a.disabled = !0), (i.text = "（需20级）"))
            : (a.disabled = !1),
          0 == o.s
            ? ((i.text = "(" + o.g + "金币)"),
              (a.label = "领养"),
              (a.skin = "comp/commonpic/btn_dialog_sure.png"),
              (a.labelColors = "#FFFFFF,#FFFFFF,#FFFFFF"))
            : 1 == o.s
            ? ((i.text = "已驯养"),
              (a.label = "出战"),
              (a.skin = "comp/commonpic/btn_dialog_gold.png"),
              (a.labelColors = "#4A4A4A,#4A4A4A,#4A4A4A"))
            : 2 == o.s &&
              ((i.text = "已出战"),
              (a.label = "休息"),
              (a.skin = "comp/commonpic/btn_dialog_gold.png"),
              (a.labelColors = "#4A4A4A,#4A4A4A,#4A4A4A"));
      }),
      (e.prototype.onLoadBuyMountsData = function (t) {
        0 == t.code &&
          (ToastView.toastView(t.msg), WebSocketService.send({ c: 4423 }));
      }),
      (e.prototype.onLoadOperateMountsData = function (t) {
        0 == t.code &&
          (ToastView.toastView("操作成功"),
          WebSocketService.send({ c: 4423 }),
          WebSocketService.send({ c: 4419 }));
      }),
      (e.prototype.onLoadMySelfMountsData = function (t) {
        if (0 != t.code)
          return (
            (this.image_mounts_yixuyang.visible = !1),
            void ToastView.toastView(t.msg)
          );
        if (t.data) {
          (this.image_mounts_yixuyang.visible = !1),
            (this.label_mountsing_weichengji.visible = !0),
            (this.myselfDict = t.data);
          var e = t.data;
          (this.image_mounts_yixuyang.visible = !0),
            (this.label_mountsing_weichengji.visible = !1),
            (this.label_mountsed_name.text = e.name);
          var o = "";
          (o = e.trans > 0 ? e.trans + "转" + e.lvl + "级" : e.lvl + "级"),
            (this.label_mountsed_lvl.text = o),
            e.exp
              ? (this.label_mountsed_exp.text = e.exp)
              : (this.label_mountsed_exp.text = "-"),
            (this.image_mounts_default.skin =
              "fujiangfull/horse_" + e.img + ".png");
          var n = [];
          e.hp > -1e3 && n.push(["气血：", e.hp]),
            e.mp > -1e3 && n.push(["精力：", e.mp]),
            e.ap > -1e3 && n.push(["攻击：", e.ap]),
            e.sp > -1e3 && n.push(["速度：", e.sp]),
            n.length > 0 &&
              ((this.label_mm_item1.text = n[0][0]),
              (this.label_mountsed_ap.text = n[0][1])),
            n.length > 1
              ? ((this.label_mm_item2.text = n[1][0]),
                (this.label_mountsed_sp.text = n[1][1]))
              : ((this.label_mm_item2.text = ""),
                (this.label_mountsed_sp.text = "")),
            1 == e.zz
              ? (this.btn_mounts_xunyang.label = "转职")
              : (this.btn_mounts_xunyang.label = "驯养");
        }
      }),
      (e.prototype.onLoadXuYangMountsData = function (t) {
        0 == t.code &&
          (WebSocketService.send({ c: 4419 }),
          Laya.stage.event("GameMainView", "refreshMoney"),
          Laya.stage.event("HomePageView", "refreshMoney")),
          ToastView.toastView(t.msg);
      }),
      (e.prototype.onDidClickXunYangAction = function (t) {
        if ((console.log(t.target.label), "转职" == t.target.label))
          NormalDialog.showNormalDialog(
            "确定将坐骑进行转职么？",
            this,
            this.onSureZhuanZhiAction
          );
        else {
          var e = "2000银币";
          "战马" != this.myselfDict.name && (e = "20金"),
            NormalDialog.showNormalDialog(
              "确定消耗" + e + "驯养一次坐骑？",
              this,
              this.onNormalSureBtnClick
            );
        }
      }),
      (e.prototype.onSureZhuanZhiAction = function () {
        var t = this.myselfDict;
        WebSocketService.send({ c: 4420, d: { id: t.id, t: "2" } });
      }),
      (e.prototype.onNormalSureBtnClick = function () {
        var t = this.myselfDict;
        WebSocketService.send({ c: 4420, d: { id: t.id, t: "1" } });
      }),
      (e.prototype.onNormalSureLingYangClick = function () {
        var t = this.list_mounts.selectedItem;
        WebSocketService.send({ c: 4424, d: { id: t.hid } });
      }),
      (e.prototype.lookXYSM = function () {
        var t = CaslnoRulesView.showCaslRuleView("xunyangshuoming");
        (t.y = 40), (t.height = 570), Laya.stage.addChild(t);
      }),
      (e.prototype.horseStringWithName = function (t) {
        var e = "";
        return (
          "战马" == t
            ? (e = "zhanma")
            : "的卢" == t
            ? (e = "dilu")
            : "绝影" == t
            ? (e = "jueying")
            : "赤兔" == t
            ? (e = "chitu")
            : "惊帆" == t && (e = "jingfan"),
          "fujiangfull/horse_" + e + ".png"
        );
      }),
      (e.prototype.backMethod = function () {
        this.removeSelf();
      }),
      e
    );
  })(ui.MountsController.MountsMainControllerUI);
